package com.itgone.easyblog.config;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler extends ApiController {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public R exception(Exception e) {
        logger.error("throw Exception", e);
        return failed("系统异常");
    }


    @ExceptionHandler(BlogServiceException.class)
    public R blogServiceException(BlogServiceException e) {
        logger.error("throw ExampleException", e);
        return failed(e.getMessage());
    }
}
